#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

#define FIFO_NAME "05_TEST.fifo"
#define STR_WRITE_BUFF "Hello FIFO inter Proccess"

int main(int argc, char const *argv[])
{
    int iRet;
    iRet = mkfifo( FIFO_NAME, 0664);
    if ( iRet == -1 && errno != EEXIST )
    {
        perror( "fail mkfifo in write.c" );
        return -1;
    }

    int fdWrite = open( FIFO_NAME, O_WRONLY );
    if ( fdWrite == -1 )
    {
        perror( "fail open in write.c" );
        return -1;
    }

    iRet = write( fdWrite, STR_WRITE_BUFF, sizeof(STR_WRITE_BUFF) );
    if ( iRet == -1 )
    {
        perror( "fail write in write.c" );
        return -1;
    }
    printf( "Write to FIFO #%d bytes: %s\n", iRet, STR_WRITE_BUFF );

    close( fdWrite );
    remove( FIFO_NAME );
    
    return 0;
}



/*
向指定的 FIFO 文件写入一个字符串

流程
    mkfifo
    open
    write
    close
    remove

*/